<template>
	<view class="">
		<view class="Nav">
			<view class="Layout flexBox padd50">
				<view class="List " v-for="(item,index) in NavInfo" :class="InfoType==index?'bgco':''" :key="index" @click="Nav(index)">
					<text class="num" v-if="item.InfoNum!=0">{{item.InfoNum}}</text>
					<image :src="item.image" mode=""></image>
					<view class="">{{item.name}}</view>
				</view>
			</view>
		</view>
		<view class="ListBox">
			<view class="Layout">
			<!-- 	<view class="flexBox" style="border-bottom: 1rpx solid #EEEEEE;"><view></view>
					<view class="AllRead" @click="AllRead()">全部已读</view>
				</view> -->
				<view class="InfoList " v-for="(item,index) in InfoList" :key="index" @click="open(index,item.message_id)">
					<view class="flexBox">	<view ></view>
					<view v-if="item.message_open==0" style="color: #ff4300;">未读</view>
					<view v-else-if="item.message_open==1">已读</view>
					</view>
					<view class="InfoBox flexBox">
						<image src="@/static/images/Station.png" v-if="InfoType==0"></image>
						<image src="@/static/images/Notice.png" v-if="InfoType==1"></image>
						<image src="@/static/images/system2.png" v-if="InfoType==2"></image>
						<view class="Info">
							<view class="">
								<view class="flexBox">
									<view class="Title" >{{item.from_member_name}}</view>
									<view class="Time">{{item.message_time|formaDate}}</view>
								</view>
								<view v-if="openList[index]">{{item.message_body}}</view>
								<view v-else class="content">{{item.message_body}}</view>
							</view>
						</view>
					</view>
					
				</view>
				<view class="IfNull" v-if="InfoList.length<=0">
					暂无消息
				</view>
			</view>
		</view>
		<go-top :isShow='isShow'></go-top>
	</view>
</template>

<script>
	import goTop from '@/components/go-top/go-top.vue'
	export default {
		components: {
			goTop
		},
		data() {
			return {
				NavInfo:[
					{"name":"公告消息","image":"/static/images/Station.png",InfoNum:0},
					{"name":"站内消息","image":"/static/images/Notice.png",InfoNum:0},
					{"name":"系统消息","image":"/static/images/system2.png",InfoNum:0}],
				InfoType:0,
				InfoList:[],
				openList:[],
				curpage:1,
				Num:0,
				isShow:false//返回顶部火箭头
			}
		},
		onLoad() {
			this.getList()
		},
		onPageScroll(res) {
			if(res.scrollTop>200){
				this.isShow=true
			}else{
				this.isShow=false
			}
		},
		onReachBottom() {
			if(this.curpage){
				this.getList(true)
			}else{
				uni.showToast({
					title:'已是最后一页！',
					icon:'none'
				})
			}
		},
		methods: {
			AllRead(){//全部已读
				
			},
			Nav(index){
				this.curpage=1
				this.InfoType=index;
				this.getList();
			},
			open(index,message_ids){
				this.$util.request({
					url:"/mobile/index.php?act=member_message&op=message_open",
					method:'post',
					data:{message_ids}
				}).then(res=>{	
						this.openList.splice(index,1,!this.openList[index])
						this.InfoList[index].message_open=1
						this.getInfoNum();
					
				})
				
				
				
			},
			getInfoNum(){
				 this.$util.request({
				 	url:"/mobile/index.php?act=member_message&op=showReceivedNewNum",
				 	method:'get',
				 	data:{}
				 }).then(res=>{	
					this.NavInfo[0].InfoNum=res.datas.newcommon
					this.NavInfo[1].InfoNum=res.datas.newpersonal
					this.NavInfo[2].InfoNum=res.datas.newsystem
				 })
			},
			getList(state){
				let that=this
				let url=""
				if(this.InfoType==0){
					url="/mobile/index.php?act=member_message&op=message"
				}else if(this.InfoType==1){
					url="/mobile/index.php?act=member_message&op=personalmsg"
				}else if(this.InfoType==2){
					url="/mobile/index.php?act=member_message&op=systemmsg"
				}
				this.$util.request({
					url:url,
					method:'get',
					data:{curpage:this.curpage}
				}).then(res=>{	
					this.NavInfo[0].InfoNum=res.datas.new_num.newcommon
					this.NavInfo[1].InfoNum=res.datas.new_num.newpersonal
					this.NavInfo[2].InfoNum=res.datas.new_num.newsystem
					if(state){//列表数据
						that.InfoList = that.InfoList.concat(res.datas.message_array) 
					}else{
						that.InfoList=res.datas.message_array;
					}
					
					if(res.datas.paged.hasmore){
						that.curpage++;
					}else{
						that.curpage=false;
					}
					that.InfoList.map((item)=>{
						that.openList.push(false)
					})
					
				})
			}
		}
	}
</script>

<style scoped>
	.bgco{
		border: 1rpx solid #ff4300;
		padding: 0 20rpx;
	}
	.IfNull{
		text-align: center;
		font-size: 36rpx;
		/* padding: 20rpx; */
		}
	.Layout{
		margin: 0 20rpx;
		box-sizing: border-box;
	}
	.AllRead{
		margin: 10rpx ;
	}
	.ListBox{
		background-color: #FFFFFF;
		margin-top: 20rpx;
	}
	.InfoList{
		padding: 20rpx 0;
		border-bottom:1rpx solid #EEEEEE ;
	}
	
	.InfoBox>image{
		width: 140rpx;
		height: 140rpx;
	}
	.InfoList .Info{
		width: 550rpx;
	}
	.InfoList .Info .content{
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
	}
	.padd50{
		padding: 0 50rpx;
	}
	.flexBox{
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	.Nav{
		margin-top: 10rpx;
		padding: 20rpx 0;
		background-color: #FFFFFF;
	}
	.List image{
		width: 100rpx;
		height: 100rpx;
	}
	.List{
		text-align: center;
		position: relative;
		padding: 0 30rpx;
	}
	.num{
		background-color: red;
		padding: 0 10rpx;
		border-radius: 40rpx;
		color: #FFFFFF;
		position: absolute;
		top: 0;
		right: 0;
		z-index: 5555;
		line-height: 36rpx;
	}
</style>
